package com.daluzy.chmanager.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.daluzy.chmanager.R;
import com.daluzy.chmanager.bean.TestPoint;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ManageTestPointAdapter extends RecyclerView.Adapter<ManageTestPointAdapter.MyViewHolder> {


    private Context context;
    private List<TestPoint> myData = new ArrayList<>();

    public ManageTestPointAdapter(Context context, List<TestPoint> myData) {
        this.context = context;
        this.myData = myData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_test_point_manage_item_daluzy, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        TestPoint testPoint = myData.get(position);
        holder.tvPointName.setText(testPoint.getPoint_name());
        holder.tvPointArea.setText(testPoint.getArea_name());
        if (!TextUtils.isEmpty(testPoint.getTest_person_name()))
            holder.tvTestPerson.setText(String.format("测试人：%s", testPoint.getTest_person_name()));
        else holder.tvTestPerson.setText("测试人：暂无");
        if (!TextUtils.isEmpty(testPoint.getPoint_tem()))
            holder.tvPointTem.setText(String.format("温度：%s", testPoint.getPoint_tem()));
        else holder.tvPointTem.setText("暂未测温");
    }

    @Override
    public int getItemCount() {
        return myData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_point_name)
        TextView tvPointName;
        @BindView(R.id.tv_point_area)
        TextView tvPointArea;
        @BindView(R.id.tv_point_tem)
        TextView tvPointTem;
        @BindView(R.id.tv_test_person)
        TextView tvTestPerson;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
